package com.xuan.web;

import com.alibaba.druid.util.StringUtils;
import com.xuan.dao.UserDao;
import com.xuan.model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/FindPassword")
public class FindPassword extends HttpServlet {

    private UserDao empDao=new UserDao();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String act = request.getParameter("act");
        switch (act){
            case "update":
                String mob = request.getParameter("mob");
                String code = request.getParameter("yzm");
                String psw = request.getParameter("password1");
                System.out.println(request.getSession().getAttribute("code"));
                if(request.getSession().getAttribute("code").equals(code)){
                    empDao.updatePassword(new User(mob,psw));
                    System.out.println("修改成功");
                    request.setAttribute("msg","修改密码成功");
                    request.getRequestDispatcher("login.jsp").forward(request,response);
                }else {
                    System.out.println("修改失败");
                    request.setAttribute("msg","修改密码失败");
                    request.setAttribute("mob",mob);
                    request.getRequestDispatcher("findPassword.jsp").forward(request,response);
                }
                break;
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }
}
